<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\Loader;
class Index extends Controller
{
	
	public function index()
    {
        return $this->fetch();
    }
    //注销
    public function logout()
    {
        Session::clear();
    	$this->redirect("index/index");
    }
    public function login(){
        $data=input("post.");
        //dump($data);
        $validate=\think\Loader::validate('User');

    	if(!$validate->check($data)){
    		$this->error($validate->getError());
    	}
        $data=[
            'uname'=>input('uname'),
            'pw'=>md5(input('pw'))
        ];
        $res=Db::name("user")->where($data)->find();
        //dump($res);
        if(!$res){
            $this->error('账号密码错误');
        }else if($res["status"]==1){
            $this-error("账号已被禁用");
        }else{
        	//把管理员信息保存到session
        	dump($res);exit;
        	Session::set("uid",$res["uid"]);
        	Session::set("realname",$res["realname"]);
        	Session::set("uname",$res["uname"]);
        	Session::set("rid",$res["rid"]);
            switch($res["rid"]){
                case 1:$this->success('登陆成功','net/index');
                case 2:$this->success('登陆成功','room/index');
                case 3:$this->success('登陆成功','suggest/index');
                default:$this->success('登陆成功','user/index');
               
            }
        }
    }
}
